<template>
	<view class="wrap">
		<block v-if="dataBuffer">
			<view class="top">
				<image :src="activeData.img" mode="widthFix" class="topBanner"></image>
				<image src="../../static/active.png" mode="widthFix" class="bottomBanner"></image>
			</view>
			<u-waterfall v-model="flowList" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<!-- <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.img" :index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.goodsname}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<view class="demo-shop">
							小U商城
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
						<!-- <u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.img" :index="index"></u-lazy-load>
						<view class="demo-title">
							{{item.goodsname}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
						<view class="demo-tag">
							<view class="demo-tag-owner">
								自营
							</view>
							<view class="demo-tag-text">
								放心购
							</view>
						</view>
						<view class="demo-shop">
							小U商城
						</view>
						<u-icon name="close-circle-fill" color="#fa3534" size="34" class="u-close" @click="remove(item.id)"></u-icon>
					</view>
				</template>
			</u-waterfall>
			<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="addRandomData"></u-loadmore>
		</block>
		<!-- 无数据提示 -->
		<u-empty 
			text="暂无数据~~去逛逛~~" mode="list" 
			:show="!dataBuffer" 
			color="orange" icon-color="orange"
		></u-empty>
	</view>
</template>

<script>
	// 引入测试数据 可以测试使用
	import list from '@/utils/active.data.js'
	export default {
		data() {      
			return {
				activeData:{},
				loadStatus: 'loadmore',
				flowList: [],  //活动详情数据
				page:1, //页码
				size:5, //条数
				totalPage:0,
				dataBuffer:true
			}
		},
		onLoad(option){
			//获取传递的参数
			console.log(JSON.parse(option.params));
			this.activeData=JSON.parse(option.params)
			
				this.getList()
				
			uni.setNavigationBarTitle({
				title:this.activeData.title
			})
			 
			// this.flowList = list;
		},
		
	onReachBottom() {
		if(this.page<this.totalPage){
			this.loadStatus="loadmore"
			setTimeout(res=>{
				++this.page
				this.getList()
			},1000)
		}else{
			this.loadStatus="nomore"
		}
		
	},
		methods: {
			getList(){
				console.log(this.activeData.second_cateid,);
				this.$http({
					url:"getgoodlist",
					data:{
						cateid:this.activeData.second_cateid,
						page:this.page,
						size:this.size,
						type:2	
					}
				}).then(res=>{
					//结构商品数据
					let {goodData,totalPage}=res.list
					if(totalPage==0){
						this.dataBuffer=false
						
					}else{
						if(this.totalPage==1){
							this.loadStatus="nomore"
						}else{
							this.loadStatus="loadmore"
						}
						
						console.log(this.totalPage);
						// 处理新数据商品图片路径
						goodData.forEach(item=>item.img = this.$URL+item.img)
						// 拼接下一页数据
						
						// 赋值总页码
						this.totalPage = totalPage;
						this.flowList=this.flowList.concat(goodData) 
						console.log(this.flowList)
					}
				})
			},
			remove(id) {
				this.$refs.uWaterfall.remove(id);
			},
			clear() {
				this.$refs.uWaterfall.clear();
			}
		}
	}
</script>

<style lang="scss" scoped>
	// 引入样式
	@import '@/static/css/active.scss'
</style>
